<template>
    <div>
        <div class="edmoto">
            <div class="pute">
                <div class="we it">
                    <span class="iconfont icon-xiangzuo" @click="$router.go(-1)"></span>
                </div>
                <div class="it ewn">
                    <span>修改地址</span>
                </div>
                <div class="it"></div>
            </div>
            <div class="fromts">
                <div class="item">
                    <span class="name">姓名:</span>
                    <input type="text" placeholder="姓名" v-model="name">
                </div>
                <div class="item ">
                    <span class="name">电话:</span>
                    <input type="text" placeholder="电话" v-model="phone">
                </div>
                <div class="item addre">
                    <span class="name">地址:</span>
                    <textarea placeholder="请填写详细地址"  v-model="text"></textarea>
                </div>
            </div>
            <div class="van-address-list__bottom">
                <div class="btom" @click="edit">修改</div>
            </div>   
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{
            name:"",
            phone:"",
            text:"",
            isDefault:null,
            id:null,
            dataed:{},
            indexto:null
        }
    },
    methods:{
        gettost(){
            this.name = this.dataed.name;
            this.phone = this.dataed.tel;
            this.text = this.dataed.address;
            this.id = this.dataed.id;
            if(this.dataed.isDefault){
                this.isDefault=this.dataed.isDefault;
            }
        },
        edit(){
            if(this.isDefault){
                if(this.name){
                    let hponeto = /^(13[0-9]|15[0-9]|17[0-9]|18[0-9]|14[0-9])[0-9]{8}$/;
                    if(hponeto.test(this.phone)){
                        let data = {
                        name:this.name,
                        address:this.text,
                        isDefault:this.isDefault,
                        tel:this.phone,
                        id:this.id
                       }
                       this.$router.push({name:'adderss',params:{obj:data,index:this.indexto}})
                        console.log(data)
                    }else{
                        console.log("请填正确信息")
                    }
                
                }else{
                    console.log("请填完信息")
                }

            }else{
                if(this.name){
                    let hponeto = /^(13[0-9]|15[0-9]|17[0-9]|18[0-9]|14[0-9])[0-9]{8}$/;
                    if(hponeto.test(this.phone)){
                        let data = {
                            name:this.name,
                            address:this.text,
                            tel:this.phone,
                            id:this.id
                        }
                        console.log(data);
                        this.$router.push({name:'adderss',params:{obj:data,index:this.indexto}})
                    }else{
                        console.log("请填正确信息")
                    }
                
                }else{
                    console.log("请填完信息")
                }
                
            }
            
            
           
        }
    },
    created(){
       console.log(this.$route.params.obj);
       console.log(this.$route.params.index);
       this.indexto=this.$route.params.index;
       this.dataed =this.$route.params.obj;
       this.gettost()
    }
}
</script>

<style lang="less">
    .edmoto{
        width: 100%;
        height: 100%;
        position: relative;
        z-index: 100;
        .pute{
            width: 100%;
            height: 40px;
            padding-left: 10px;
            padding-right: 10px;
            box-sizing: border-box;
            display: flex;
            justify-content: space-between;
            align-items: center;
            .it{
                width: 10%;
                height: 40px;
               
            }
            .we{
                text-align: center;
                line-height: 40px;
                span{
                    &.iconfont{
                        font-size: 20px;
                    }
                }
            }
            .ewn{
                width: 20%;
                text-align: center;
                line-height: 40px;
                 span{
                    font-size: 16px;
                }
            }
        }
        .fromts{
            width: 100%;
            margin-top: 20px;
            .item{
                width: 100%;
                padding-left: 10px;
                padding-right: 10px;
                margin-top: 10px;
                margin-bottom: 10xp;
                display: flex;
                justify-content: space-between;
                align-items: center;
                box-sizing: border-box;
                span{
                    &.name{
                        display: block;
                        width: 15%;
                        height: 30px;
                        text-align: left;
                        line-height: 30px;
                        font-size: 16px;
                        font-weight: 600;
                    }
                }
                input{
                    width: 80%;
                    height: 30px;
                    margin: auto;
                    padding-left: 5px;
                    box-sizing: border-box;
                    outline-style: none ;
                    // border: 0px;
                    border: 1px solid #ccc;
                    border-radius: 3px;
                    // padding: 14px 14px;
                    font-size: 16px;
                    
                }
            }
            .addre{
                textarea{
                    width: 80%;
                    height: 60px;
                    margin: auto;
                    padding-left: 5px;
                    box-sizing: border-box;
                    outline-style: none ;
                    // border: 0px;
                    border: 1px solid #ccc;
                    border-radius: 3px;
                    // padding: 14px 14px;
                    font-size: 16px;
                    resize:none;
                    outline:none;
                }
            }
        }
        .van-address-list__bottom{
            position: fixed;
            bottom: 0;
            left: 0;
            z-index: 999;
            box-sizing: border-box;
            width: 100%;
            padding: 0 16px;
            padding-bottom: 200px;
            border: 1px solid white;
            background-color: #fff;
            .btom{
                width: 100%;
                height: 40px;
                margin: 5px 0;
                background-color: #ee0a24;
                border-radius: 20px;
                text-align: center;
                line-height: 40px;
                color: #fff;
            }
        }
    }
</style>